cd "C:\DRS\"

use VAR_LARGE_DAILY.dta, clear
replace retg = . if retp == .
gen y = 0
replace y = 1 if retg == .
drop if y == 1
keep simid t simtype retg retp

gen skg = .
gen kurg = .
gen skp = .
gen kurp = .

sort simid t
egen simidn = group(simid)
drop simid
rename simidn simid

local i = 1
while `i' < 166{
quietly summarize retp if simid == `i', detail
replace skp = r(skewness) if simid == `i'
replace kurp = r(kurtosis) if simid == `i'
quietly summarize retg if simid == `i', detail
replace skg = r(skewness) if simid == `i'
replace kurg = r(kurtosis) if simid == `i'
local i = `i'+1
}

sort simid t
gen x = 0
replace x = 1 if simid ~=simid[_n+1]

log using T10.log, replace
** Simulations Minimizing the Variance of Returns **
** Largest No. of Funds **
label var skg "Skewness of the Returns on Global Funds"
label var kurg "Kurtosis of the Returns on Global Funds"
label var skp "Skewness of the Returns on Simulated Global Funds"
label var kurp "Kurtosis of the Returns on Simulated Global Funds"
tabstat skg kurg if x == 1, stats (mean sd) by(simtype)
tabstat skp kurp if x == 1, stats (mean sd) by(simtype)
tabstat x, stats (sum) by(simtype)
log close

use VAR_LONG_DAILY.dta, clear
replace retg = . if retp == .
gen y = 0
replace y = 1 if retg == .
drop if y == 1
keep simid t simtype retg retp

gen skg = .
gen kurg = .
gen skp = .
gen kurp = .

sort simid t
egen simidn = group(simid)
drop simid
rename simidn simid

local i = 1
while `i' < 166{
quietly summarize retp if simid == `i', detail
replace skp = r(skewness) if simid == `i'
replace kurp = r(kurtosis) if simid == `i'
quietly summarize retg if simid == `i', detail
replace skg = r(skewness) if simid == `i'
replace kurg = r(kurtosis) if simid == `i'
local i = `i'+1
}

sort simid t
gen x = 0
replace x = 1 if simid ~=simid[_n+1]

log using T10.log, append
** Simulations Minimizing the Variance of Returns **
** Longest Available Sample **
label var skg "Skewness of the Returns on Global Funds"
label var kurg "Kurtosis of the Returns on Global Funds"
label var skp "Skewness of the Returns on Simulated Global Funds"
label var kurp "Kurtosis of the Returns on Simulated Global Funds"
tabstat skg kurg if x == 1, stats (mean sd) by(simtype)
tabstat skp kurp if x == 1, stats (mean sd) by(simtype)
tabstat x, stats (sum) by(simtype)
log close

use EXP_LARGE_DAILY.dta, clear
replace retg = . if retp == .
gen y = 0
replace y = 1 if retg == .
drop if y == 1
keep simid t simtype retg retp

gen skg = .
gen kurg = .
gen skp = .
gen kurp = .

sort simid t
egen simidn = group(simid)
drop simid
rename simidn simid

local i = 1
while `i' < 166{
quietly summarize retp if simid == `i', detail
replace skp = r(skewness) if simid == `i'
replace kurp = r(kurtosis) if simid == `i'
quietly summarize retg if simid == `i', detail
replace skg = r(skewness) if simid == `i'
replace kurg = r(kurtosis) if simid == `i'
local i = `i'+1
}

sort simid t
gen x = 0
replace x = 1 if simid ~=simid[_n+1]

log using T10.log, append
** Simulations Maximizing Expected Returns **
** Largest No. of Funds **
label var skg "Skewness of the Returns on Global Funds"
label var kurg "Kurtosis of the Returns on Global Funds"
label var skp "Skewness of the Returns on Simulated Global Funds"
label var kurp "Kurtosis of the Returns on Simulated Global Funds"
tabstat skg kurg if x == 1, stats (mean sd) by(simtype)
tabstat skp kurp if x == 1, stats (mean sd) by(simtype)
tabstat x, stats (sum) by(simtype)
log close

use EXP_LONG_DAILY.dta, clear
replace retg = . if retp == .
gen y = 0
replace y = 1 if retg == .
drop if y == 1
keep simid t simtype retg retp

gen skg = .
gen kurg = .
gen skp = .
gen kurp = .

sort simid t
egen simidn = group(simid)
drop simid
rename simidn simid

local i = 1
while `i' < 166{
quietly summarize retp if simid == `i', detail
replace skp = r(skewness) if simid == `i'
replace kurp = r(kurtosis) if simid == `i'
quietly summarize retg if simid == `i', detail
replace skg = r(skewness) if simid == `i'
replace kurg = r(kurtosis) if simid == `i'
local i = `i'+1
}

sort simid t
gen x = 0
replace x = 1 if simid ~=simid[_n+1]

log using T10.log, append
** Simulations Maximizing Expected Returns **
** Longest Available Sample **
label var skg "Skewness of the Returns on Global Funds"
label var kurg "Kurtosis of the Returns on Global Funds"
label var skp "Skewness of the Returns on Simulated Global Funds"
label var kurp "Kurtosis of the Returns on Simulated Global Funds"
tabstat skg kurg if x == 1, stats (mean sd) by(simtype)
tabstat skp kurp if x == 1, stats (mean sd) by(simtype)
tabstat x, stats (sum) by(simtype)
log close
